package com.zhr.tea.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.zhr.tea.R;
import com.zhr.tea.entity.DingZhiBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 * Created by 毛懿 on 2016/11/4 22:09.
 * 邮箱：1334964028@qq.com
 */

public class DzAdapter extends RecyclerView.Adapter<DzAdapter.DingZhiViewHolder> {
    private Context context;
    private List<DingZhiBean.ContentBean> data;
    private OnItemClick itemClick;

    public DzAdapter(Context context, List<DingZhiBean.ContentBean> data, OnItemClick itemClick) {
        this.context = context;
        this.data = data;
        this.itemClick = itemClick;
    }

    @Override
    public DingZhiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DingZhiViewHolder(LayoutInflater.from(context).inflate(R.layout.item_yuancha, parent, false));
    }

    @Override
    public void onBindViewHolder(DingZhiViewHolder holder, final int position) {
        Glide.with(context).load(data.get(position).getImgUrl()).into(holder.ivYuanchaItem);
        if (position != data.size() - 1) {
            holder.view.setVisibility(View.VISIBLE);
        } else {
            holder.view.setVisibility(View.GONE);
        }
        holder.ivYuanchaItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClick.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class DingZhiViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_yuancha_item)
        ImageView ivYuanchaItem;
        @BindView(R.id.view_yuancha)
        View view;

        public DingZhiViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClick {
        void click(int position);
    }
}
